home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / RCSC.ZIP / BIN / PREPROC.AWK < prev    next >
Text File  |  1997-01-12  |  2KB  |  95 lines

  1. #********************************************************
  2. #This is part of the Retargetable Concurrent Small C
  3. #distribution (8051 version)
  4. #Copyright 1997 Andy W. K. Yuen
  5. #********************************************************
  6. #awk program to group and move all literals and other memory
  7. #initialization assembler directives to the end of program
  8. #
  9. BEGIN { FS = "("}
  10. {
  11. #identify and process PCDOES
  12. if ($1 == "TASKS") {
  13.     taskcount++;
  14.     task[taskcount] = $0
  15.     }
  16. else if ($1 == "MNTRS") {
  17.     moncount++;
  18.     mon[moncount] = $0
  19.     }
  20. else if ($1 == "INTRS") {
  21.     intrcount++;
  22.     intr[intrcount] = $0
  23.     print
  24.     }
  25. else if (dataflag) {
  26.     if ($0 == "BEGINDUMP")
  27.         codeflag = 1
  28.     else if ($0 == "ENDSEG(1)")
  29.         dataflag = 0
  30.     else if ($1 == "SHADOW") {
  31.         codeflag = 0
  32.         sum += substr($2, 1, length($2) - 1)
  33.         }
  34.  
  35.         if (codeflag) {
  36.         codecount++
  37.         code[codecount] = $0
  38.         }
  39.     else {
  40.         datacount++
  41.         data[datacount] = $0
  42.         }
  43.     }
  44. else if ($0 == "TOSEG(1)") {
  45.     dataflag = 1
  46.     datacount++
  47.     data[datacount] = $0
  48.     }
  49. else if ($0 == "END") 
  50.     endmarker = $0
  51. else {
  52.     if ($1 == "MODULENAME")
  53.         name = substr($2, 1, length($2) - 1)
  54.     print
  55.     }
  56. }
  57.  
  58. END { 
  59.     printf "%s_litsize=%d\n", name, sum > name
  60.     if (codecount != 0) {
  61.         print "\n;;literals and memory initialization assembler directives\n"
  62.         for (i = 1; i <= datacount; i++ ) print data[i] 
  63.         print "\nBEGINLIT"
  64.         for (i = 1; i <= codecount; i++ ) 
  65.             if (code[i] != "BEGINDUMP") print code[i] 
  66.         print "ENDLIT"
  67.         
  68.     }
  69.     printf "%s_tasksize=%d\n", name, taskcount * 6 > name
  70.     if (taskcount != 0) {
  71.         printf "\nBEGINTASK(%d)\n", taskcount
  72.         for (i = 1; i <= taskcount; i++ ) 
  73.             print task[i]
  74.         print "ENDTASK"
  75.     }
  76.     printf "%s_monsize=%d\n", name, moncount * 3 > name
  77.     if (moncount != 0) {
  78.         printf "\nBEGINMON(%d)\n", moncount
  79.         for (i = 1; i <= moncount; i++ ) 
  80.             print mon[i]
  81.         print "ENDMON"
  82.     }
  83.     if (intrcount != 0) {
  84.         for (i = 1; i <= intrcount; i++) {
  85.            if ($0 != "") {
  86.             split(intr[i], field, ",")
  87.             num = substr(field[2], 1, index(field[2], ")")-1)
  88.             printf "SETVECTOR(%s_%d, %d)\n", "__intr", num, num
  89.            }
  90.         }
  91.     }
  92.     print endmarker
  93. }
  94.  
  95.